<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-collapse v-model="activeKey">
          <!-- 基本信息 -->
          <a-collapse-panel key="1" header="基本信息">
            <a-row :gutter="48">
              <a-col :span="8" :hidden="true">
                <a-form-model-item label="流程名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bpmBizTitle" >
                  <a-input :max-length="255" :disabled="formDisabled" v-model="model.bpmBizTitle" placeholder="请输入流程名称"></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseBill">
                  <a-input v-model="model.purchaseBill" placeholder="请输入单据编号" disabled ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="申请时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
                  <j-date
                    placeholder="请选择申请时间"
                    v-model="model.createTime"
                    :show-time="true"
                    date-format="YYYY-MM-DD HH:mm:ss"
                    style="width: 100%"
                    disabled/>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="employeeId">
                  <select-user-by-dep :multi="false" placeholder="请选择申请人" v-model="model.employeeId" disabled />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="departId">
                  <j-select-depart v-model="model.departId" placeholder="请选择申请部门" disabled/>
                </a-form-model-item>
              </a-col>

              <template v-if="revokedType">
                <a-divider>作废信息</a-divider>
                <a-col :span="8">
                  <a-form-model-item label="单据名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseBillId">
                    <SelectPurchaseCalibrationOpinionInput :disabled="formDisabled" v-model="model.purchaseBillId" placeholder="请选择定标意见表单" :isVoid="true" @back="purchaseInfoBack"/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invalidationProposer">
                    <select-user-by-dep
                      placeholder="请选择申请人"
                      v-model="model.invalidationProposer" disabled/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="申请部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invalidationDepartId">
                    <j-select-depart placeholder="请选择申请部门" v-model="model.invalidationDepartId" disabled/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="申请时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invalidationCreateTime">
                    <j-date
                      placeholder="请选择申请时间"
                      v-model="model.invalidationCreateTime"
                      :show-time="true"
                      date-format="YYYY-MM-DD HH:mm:ss"
                      style="width: 100%"
                      disabled/>
                  </a-form-model-item>
                </a-col>
              </template>
              <a-col :span="8">
                <a-form-model-item label="所属团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teamId">
                  <select-team-input
                    placeholder="请选择所属团队"
                    :disabled="formDisabled || revokedType"
                    v-model="model.teamId"
                    @back="teamBack"
                    :tdlx="1"/>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-collapse-panel>
          <a-collapse-panel key="2">
            <span slot="header">招标采购申请信息<span style="color: #fa3534;">（注：只可关联一个招标采购申请）</span></span>
            <a-row :gutter="48">
              <ErpPurchaseCalibrationOpinionDetailList ref="calibrationOpinionDetailList" :teamId="model.teamId" @onBudget="onBudget" :disabled="formDisabled || revokedType"></ErpPurchaseCalibrationOpinionDetailList>
            </a-row>
          </a-collapse-panel>
          <a-collapse-panel key="3" header="中标信息">
            <a-row :gutter="48">
              <ErpPurchaseCalibrationOptionUnitList ref="calibrationOptionUnitList" :disabled="formDisabled || revokedType"></ErpPurchaseCalibrationOptionUnitList>
            </a-row>
            <a-row :gutter="48">
              <a-col :span="24">
                <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
                  <a-textarea :disabled="formDisabled || revokedType" :max-length="1000" v-model="model.remark" rows="4" placeholder="请输入备注"/>
                </a-form-model-item>
              </a-col>
            </a-row> 
          </a-collapse-panel>
          <a-collapse-panel key="4" header="相关附件">
            <a-row :gutter="48">
              <a-col :span="24">
                <a-form-model-item label="相关附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseFile">
                  <j-upload v-if="!formDisabled || revokedType" :disabled="formDisabled || revokedType" v-model="model.purchaseFile"></j-upload>
                  <a-button v-else icon="download" @click="viewFile(model.purchaseFile)">文件列表</a-button>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-collapse-panel>
        </a-collapse>
        <a-row :gutter="48" v-if="revokedType">
          <a-col :span="24">
            <a-form-model-item label="作废理由" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="invalidationReason">
              <a-textarea :max-length="1000" :disabled="formDisabled" v-model="model.invalidationReason" rows="4" placeholder="请输入作废理由"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
      <CommonFirstFlowList v-if="model.bpmStatus !== '1'&&formBpm&&revokedType" :formData="OriginalFormData"></CommonFirstFlowList>
      <common-flow-list v-if="formBpm && model.bpmStatus !== '1'" :formData="formData" style="margin-top: 10px"></common-flow-list>
      <view-file-modal ref="viewFileModal"></view-file-modal>
    </j-form-container>
    <a-row :gutter="48">
      <a-col :span="24" style="text-align: center;margin-top: 15px">
        <a-button type="primary" v-if="formBpm" :style="{ marginRight: showFlowSubmitButton?'10px':'0px' }" @click="onPrint">打印</a-button>
        <!-- <a-button @click="submitForm('submit')" v-if="showFlowSubmitButton">提 交</a-button> -->
      </a-col>
    </a-row>
    <ErpPurchaseCalibrationOpinionFormPrint v-if="formBpm" class="print_style" id="calibrationOpinionContent" :formData="model" :OriginalFormData="OriginalFormData" :formDataHistory="formData"></ErpPurchaseCalibrationOpinionFormPrint>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import ViewFileModal from '@/views/scy/components/ViewFileModal'
  import { viewFile } from '@/utils/util'
  import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
  import ErpPurchaseCalibrationOpinionDetailList from './reference/ErpPurchaseCalibrationOpinionDetailList' // 招标采购申请信息
  import ErpPurchaseCalibrationOptionUnitList from './reference/ErpPurchaseCalibrationOptionUnitList' // 中标信息
  import CommonFlowList from '@/views/components/CommonFlowList.vue';
  import CommonFirstFlowList from '@/views/components/CommonFirstFlowList.vue';
  import ErpPurchaseCalibrationOpinionFormPrint from './ErpPurchaseCalibrationOpinionFormPrint'
  import moment from 'moment'
  import Decimal from 'decimal.js'
  import Print from '@/utils/print/printarea.js';
  import { mapGetters } from 'vuex'
  export default {
    name: 'ErpPurchaseCalibrationOpinionForm',
    mixins: [DisabledAuthFilterMixin, viewFile],
    components: {
      ViewFileModal,
      SelectUserByDep,
      SelectTeamInput,
      SelectCompanyInput,
      SelectCustomerInput,
      ErpPurchaseCalibrationOpinionDetailList,
      ErpPurchaseCalibrationOptionUnitList,
      CommonFlowList,
      CommonFirstFlowList,
      SelectPurchaseCalibrationOpinionInput: () => { return import('./SelectPurchaseCalibrationOpinionInput')},
      ErpPurchaseCalibrationOpinionFormPrint
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        activeKey: ['1', '2','3', '4'],
        model:{
          purchaseBill: null
        },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        confirmLoading: false,
        validatorRules: {
        // task#2118 是否环评改为必填项，默认为否
        purchaseBill: [
          { required: true, message: '请重新生成单据编号!' }
        ],
        createTime: [
          { required: true, message: '请重新生成申请时间!' }
        ],
        employeeId: [
          { required: true, message: '请重新生成申请人!'},
        ],
        departId: [
          { required: true, message: '请重新生成申请部门!' }
        ],
        teamId: [
          { required: true, message: '请选择所属团队!' }
        ]
      },
      revokedType: false,
      provisionBroadList: [], // 获取采购类型
      revokedType: false,
      OriginalFormData:{},
      teamIdBackups: null,
      userName: '',
        url: {
          add: "/api/erp/purchase/procurement/erpPurchaseCalibrationOpinion/add",
          edit: "/api/erp/purchase/procurement/erpPurchaseCalibrationOpinion/edit",
          queryById: "/api/erp/purchase/procurement/erpPurchaseCalibrationOpinion/queryById",
          queryProvisionBroadList: '/api/erp/purchase/material/erpMaterialCategory/queryAllParent',
          generatedFormNumber: '/api/erp/purchase/procurement/erpPurchaseCalibrationOpinion/gainBillNo',
          queryVerification: '/api/erp/purchase/procurement/erpPurchaseCalibrationOpinion/referencedVerification',
          queryVerificationCancelling: '/api/erp/purchase/procurement/erpPurchaseCalibrationOpinion/referencedVerificationCancelling',
          getBizHisProcessNodeInfo: "/api/erpmng/act/process/extActProcessNode/getBizHisProcessNodeInfo",
        }
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    async created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
      this.getProvisionBroadList() // 获取采购类型
    },
    methods: {
      ...mapGetters(['userInfo']),
      purchaseInfoBack(item){
        const that = this
        //判断不为空
        if(!!this.model.purchaseBillId && item.length > 0){
          //判断公司是否变化
          // this.purchaseBillIdBackups !== item[0].id
          getAction(this.url.queryVerification,{ id: item[0].id}).then(res => {
            if(res.result == "校验通过"){
              getAction(this.url.queryVerificationCancelling,{ id: item[0].id}).then(response => {
                if(response.result == "校验通过"){
                  //确认后进行改变
                  that.purchaseBillIdBackups = item[0].id
                  that.handleModelData(item[0])
                  that.model.purchaseBillId = item[0].id
                } else {
                  that.$message.warning(response.message)
                  that.model.purchaseBillId = that.purchaseBillIdBackups
                }
              })
            } else {
              that.$message.warning(res.message)
              that.model.purchaseBillId = that.purchaseBillIdBackups
            }
          })
        } else {
          that.handleModelData()
        }
      },
      handleModelData(val){
        if(val){
          // 选择单据 处理原表单数据
          this.$set(this.model,'invalidationPurchaseBill',val.purchaseBill)
          this.$set(this.model,'invalidationProposer',val.employeeId)
          this.$set(this.model,'invalidationDepartId',val.departId)
          this.$set(this.model,'invalidationCreateTime',val.createTime)
          this.$set(this.model,'bpmBizTitle','作废-'+ this.userName + '-' + this.model.purchaseBill)
          this.$set(this.model,'teamId',val.teamId)
          this.$set(this.model,'remark',val.remark || '')
          this.$set(this.model,'purchaseFile',val.purchaseFile || '')
          this.teamIdBackups = val.teamId
          this.$refs.calibrationOptionUnitList.loadData(1, val.id)
          this.$refs.calibrationOpinionDetailList.loadData(1, val.id)
        } else {
          // 选择单据 处理原表单数据
          this.$set(this.model,'invalidationPurchaseBill','')
          this.$set(this.model,'invalidationProposer','')
          this.$set(this.model,'invalidationDepartId','')
          this.$set(this.model,'invalidationCreateTime','')
          this.$set(this.model,'teamId','')
          this.$set(this.model,'remark','')
          this.$set(this.model,'purchaseFile','')
          this.$refs.calibrationOptionUnitList.dataSource = []
          this.$refs.calibrationOpinionDetailList.dataSource = []
        }
        
      },
      generatedFormNumber (params = {}) {
        const that = this
        getAction(this.url.generatedFormNumber, params).then(res => {
          if (res.success) {
            this.$set(this.model, 'purchaseBill', res.result)
            if(!that.revokedType){
              that.model.bpmBizTitle = that.userName + '-' + that.model.purchaseBill//标题
            } else {
              that.$set(that.model,'bpmBizTitle','作废-'+ that.userName + '-' + that.model.purchaseBill)
            }
          }
        })
      },
      // 获取采购类型
      getProvisionBroadList() {
        const that = this
        that.provisionBroadList = []
        getAction(this.url.queryProvisionBroadList).then(res => {
          if (res.success) {
            that.provisionBroadList = res.result
          } else {
            that.$message.warning(res.message)
          }
        })
      },
      add (title) {
        // this.dataSource = []
        this.revokedType = !!title
        // this.edit(this.modelDefault);
        // this.userName = this.userInfo().empName;// 申请人名称
        // this.model.employeeId = this.userInfo().empId; // 申请人
        // this.model.departId = this.userInfo().deptId; // 申请部门
        // this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss');
        // this.generatedFormNumber();

        if(!!title){
          this.$refs["form"].clearValidate();
          this.model = Object.assign({},{ 
            purchaseBill: '',
            purchaseBillId: '',
            invalidationReason: ''
          })
          this.purchaseBillIdBackups = null
          this.$refs.calibrationOptionUnitList.dataSource = []
          this.$refs.calibrationOpinionDetailList.dataSource = []
          this.$refs.calibrationOpinionDetailList.showAdd = false
          this.userName = this.userInfo().empName;// 当前登录人名称
          this.model.employeeId = this.userInfo().empId; // 当前登录人
          this.model.departId = this.userInfo().deptId; //当前登录人部门
          this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss');
          this.generatedFormNumber({type: '2'}) //获取单据编号
          this.validatorRules = {
            purchaseBillId: [
              { required: true, message: '请选择单据名称!', trigger: 'change' }
            ],
            invalidationReason: [
              { required: true, message: '请输入作废理由!', trigger: 'blur' },
            ]
          }
        } else {
          this.edit(this.modelDefault);
          this.userName = this.userInfo().empName;// 当前登录人名称
          this.model.employeeId = this.userInfo().empId; // 当前登录人
          this.model.departId = this.userInfo().deptId; //当前登录人部门
          this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss');
          this.generatedFormNumber() //获取单据编号
        }
      },
      edit (record) {
        this.$refs["form"].clearValidate();
        this.userName = this.userInfo().empName;// 当前登录人名称
        this.model = Object.assign({}, record);
        this.revokedType = this.model.purchaseBill?this.model.purchaseBill.substring(0,2) == 'ZF':false
        if(this.revokedType){
          this.validatorRules = {
            purchaseBillId: [
              { required: true, message: '请选择单据名称!', trigger: 'change' }
            ],
            invalidationReason: [
              { required: true, message: '请输入作废理由!', trigger: 'blur' },
            ]
          }
        } else {
          this.validatorRules = {
            teamId: [
              { required: true, message: '请选择所属团队!', trigger: 'change' }
            ]
          }
        }
        if (this.formBpm === true) {
          getAction(this.url.getBizHisProcessNodeInfo, { flowCode: 'onl_erp_purchase_calibration_opinion', dataId: this.model.purchaseBillId }).then((res) => {
            if (res.success) {
              var data = {
                dataId: res.result.dataId,
                procInsId: res.result.procInsId,
                tableName: res.result.tableName,
                vars: res.result.records
              }
              this.OriginalFormData = data;
            }
          })
        }
        this.visible = true;
        if (this.revokedType) {
          if (this.model.purchaseBillId) {
            this.$nextTick(() => {
              this.$refs.calibrationOptionUnitList.loadData(1, this.model.purchaseBillId)
              this.$refs.calibrationOpinionDetailList.loadData(1,  this.model.purchaseBillId)
            })
          } else {
            this.$refs.calibrationOptionUnitList.dataSource = []
            this.$refs.calibrationOpinionDetailList.dataSource = []
          }
        } else {
          if (this.model.id) {
            this.$nextTick(() => {
              this.$refs.calibrationOptionUnitList.loadData(1, this.model.id)
              this.$refs.calibrationOpinionDetailList.loadData(1,  this.model.id)
            })
          } else {
            this.$refs.calibrationOptionUnitList.dataSource = []
            this.$refs.calibrationOpinionDetailList.dataSource = []
          }
        }
        if (this.model.id) {
          this.teamIdBackups = this.model.teamId
        } else {
          this.$refs.calibrationOptionUnitList.dataSource = []
          this.$refs.calibrationOpinionDetailList.dataSource = []
          this.$refs.calibrationOpinionDetailList.showAdd = false
        }
      },
      onBudget () {
        console.log('123213123')
      },
      teamBack(item) {
        //判断不为空
        if(!!this.model.teamId && item.length > 0) {
          //判断团队是否变化
          if(this.teamIdBackups !== item[0].id) {
            let detailList = this.$refs.calibrationOpinionDetailList.submitForm()
            if(detailList.length > 0) {
              const that = this;
              that.$confirm({
                title: "是否确认",
                content: "是否确认切换所属团队，此操作将会清空招标采购申请信息明细中已填写的所有信息？",
                onOk() {
                  //确认后进行改变
                  that.teamIdBackups = that.model.teamId
                  //清空子表数据
                  that.$refs.calibrationOpinionDetailList.dataSource = []
                  that.$refs.calibrationOpinionDetailList.showAdd = false
                },
                onCancel() {
                  that.model.teamId = that.teamIdBackups
                }
              });
            } else {
              this.teamIdBackups = item[0].id
            }
          }
        }
      },
      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      submitForm(type) {
        const that = this;
        if (type == 'draft') {
          // 代表保存草稿不做校验
          this.submit(type)
        } else if (type == 'submit') {
          let detailList = this.$refs.calibrationOpinionDetailList.submitForm()
          let unitList = this.$refs.calibrationOptionUnitList.submitForm()
          
          if(!this.revokedType){
              this.model.bpmBizTitle = this.userName + '-' + that.model.purchaseBill//标题
            } else {
              this.$set(this.model,'bpmBizTitle','作废-'+ this.userName + '-' + this.model.purchaseBill)
            }
          if (!detailList.length > 0) {
            this.$message.warning('请添加招标采购申请信息！');
            this.$emit('unButtonDisable');
            return
          }
          if (!unitList.length > 0) {
            this.$message.warning('请添加中标信息！');
            this.$emit('unButtonDisable');
            return
          }
          if(this.revokedType){
            getAction(this.url.queryVerification,{id: that.model.purchaseBillId}).then(res => {
              if(res.success){
                getAction(this.url.queryVerificationCancelling,{id: that.model.purchaseBillId}).then(resp => {
                  if(resp.success){
                    // 触发表单验证
                    this.$refs.form.validate(valid => {
                      if (valid) {
                        that.submit(type)
                      } else {
                        that.$emit('unButtonDisable')
                      }
                    })
                  } else {
                    that.$message.warning(resp.message);
                    that.$emit('unButtonDisable');
                  }
                })
              } else {
                that.$message.warning(res.message);
                that.$emit('unButtonDisable');
              }
            })
            return
          } else {
            // 不是作废定标意见单
            // 判断采购类型
            if (this.provisionBroadList && this.provisionBroadList.length > 0) {
              let categoryCode = ''
              this.provisionBroadList.forEach(item => {
                
                if (item.id === detailList[0].provisionBroad) {
                  categoryCode = item.categoryCode
                }
              })
              var totalBidPrice = new Decimal(0)
              if (unitList && unitList.length > 0) {
                unitList.forEach(item => {
                  // 计算中标金额之和
                  totalBidPrice = totalBidPrice.add(new Decimal(item.bidding || 0))
                })
              }
              // 采购类型是行政类，中标金额需要超过十万元
              if (categoryCode == '01') {
                if (Number(totalBidPrice) < 100000) {
                  // 小于十万则终止提交
                  this.$message.warning('当前中标总金额未超过标准金额100000元不需要发起“定标意见单”流程');
                  this.$emit('unButtonDisable');
                  return
                }
              } else if (categoryCode == '02') {
                // 采购类型是业务类，中标金额再根据业务分类判断
                if (detailList[0].businessSegment == 'HBZXYWBKFZR') {
                  // 环保咨询
                  if (Number(totalBidPrice) < 100000) {
                    // 小于十万则终止提交
                    this.$message.warning('当前中标总金额未超过标准金额100000元不需要发起“定标意见单”流程');
                    this.$emit('unButtonDisable');
                    return
                  }
                } else if (detailList[0].businessSegment == 'ZLYWYWBKFZR') {
                  // 工程运维
                  if (Number(totalBidPrice) < 200000) {
                    // 小于二十万则终止提交
                    this.$message.warning('当前中标总金额未超过标准金额200000元不需要发起“定标意见单”流程');
                    this.$emit('unButtonDisable');
                    return
                  }
                } else if (detailList[0].businessSegment == 'JYJCYWBKFZR') {
                  // 检验检测
                  if (Number(totalBidPrice) < 100000) {
                    // 小于十万则终止提交
                    this.$message.warning('当前中标总金额未超过标准金额100000元不需要发起“定标意见单”流程');
                    this.$emit('unButtonDisable');
                    return
                  }
                } else if (detailList[0].businessSegment == 'SZXXYWBKFZR') {
                  // 数字信息
                  if (Number(totalBidPrice) < 200000) {
                    // 小于二十万则终止提交
                    this.$message.warning('当前中标总金额未超过标准金额200000元不需要发起“定标意见单”流程');
                    this.$emit('unButtonDisable');
                    return
                  }
                } else if (detailList[0].businessSegment == 'HBGJYWBKFZR') {
                  // 智慧管家
                  if (Number(totalBidPrice) < 100000000) {
                    // 小于1000万则终止提交
                    this.$message.warning('当前中标总金额未超过标准金额100000000元不需要发起“定标意见单”流程');
                    this.$emit('unButtonDisable');
                    return
                  }
                } else if (detailList[0].businessSegment == 'LTYWYWBKFZR') {
                  // 林碳业务
                  if (Number(totalBidPrice) < 100000) {
                    // 小于十万则终止提交
                    this.$message.warning('当前中标总金额未超过标准金额100000元不需要发起“定标意见单”流程');
                    this.$emit('unButtonDisable');
                    return
                  }
                } else if (detailList[0].businessSegment == 'SLYWYWBKFZR') {
                  // 水利业务
                  if (Number(totalBidPrice) < 100000000) {
                    // 小于1000万则终止提交
                    this.$message.warning('当前中标总金额未超过标准金额100000000元不需要发起“定标意见单”流程');
                    this.$emit('unButtonDisable');
                    return
                  }
                }
              }
            }
          }
          // 触发表单验证
          this.$refs.form.validate(valid => {
            if (valid) {
              that.submit(type)
            } else {
              that.$emit('unButtonDisable')
            }
          })
        } else {
          console.log('传参数，保存：draft，提交：submit')
        }
      },
      submit (type) {
        const that = this;
        let detailList = this.$refs.calibrationOpinionDetailList.submitForm() || []
        let unitList = this.$refs.calibrationOptionUnitList.submitForm() || []
        that.confirmLoading = true;
        let httpurl = '';
        let method = '';
        if (!this.model.id) {
          httpurl += this.url.add;
          method = 'post';
        } else {
          httpurl += this.url.edit;
          method = 'put';
        }
        this.model.detailList = detailList
        this.model.unitList = unitList
        httpAction(httpurl, this.model, method).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            if (method == 'post') {
              that.model.id = res.result;
            }
            that.$emit('ok', type, that.model);
          } else {
            that.$message.warning(res.message);
            that.$emit('unButtonDisable');
          }
        }).catch((error) => {
          that.$emit('unButtonDisable', error);
        }).finally(() => {
          that.confirmLoading = false;
        })
      },
      // 点击打印
      onPrint () {
        let print = new Print({
          el: '#calibrationOpinionContent',
          popTitle: '定标意见确认详情 · 禾美环保',
          endCallback() {

          }
        })
      }
    }
  }
</script>
